/*
 * Copyright (c) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <errno.h>

#include "hi_ext_def.h"
#include "hi_dbg_log.h"

/**
    debug level.
*/
int g_hiDbgLev = HI_DLEV_INFO;

/**
    set level.
*/
void HiSetDbgLev(int lev)
{
    if (lev < 0 || lev >= HI_DLEV_BUTT) { // error
        printf("\033[;31m" "set dbg lev FAIL, lev=%d, range={%d~%d}\n" "\033[0m", lev, 0, HI_DLEV_BUTT - 1);
    } else if (lev != g_hiDbgLev) { // warn
        printf("\033[1;35m" "dbg lev changed, %d -> %d\n" "\033[0m", g_hiDbgLev, lev);
        g_hiDbgLev = lev; // 无需加锁，安全
    }
}

/**
    assert处理器.
*/
void HiAssertErr(const char* file, int line, const char* func, const char* exp)
{
    printf("\033[1;31m" "HI_ASSERT: %s[%d](%s): '%s'\n" "\033[0m", HiPathName(file), line, func, exp);
    exit(HI_EC_ASSERT_FAIL);
}

